1 //Robado de: http://www.wretch.cc/blog/celiaailec/19569472
2 // Q562: Dividing coins
4 // Method: Dynamic Programming
17 return (n
> 0)? n
: -n
;
22 int i
, j
, t
, n
, m
, sum
, a
[N
];
29 for(sum
= 0, i
= 1; i
<= n
; i
++)
30 scanf("%d", &a
[i
]), sum
+= a
[i
];
33 memset(v
, 0, sizeof(v
));
36 for(i
= 1; i
<= n
; i
++)
37 for(j
= m
; j
>= 1; j
--)
39 v
[j
] = (a
[i
] <= j
)? v
[j
-a
[i
]] : false;
41 for(j
= m
; j
>= 1; j
--)
45 printf("%d\n", iabs(sum
- j
* 2));